package com.CMC.yhdeng;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;

import android.util.JsonReader;

public class UnitBase implements Serializable{
	private static final long serialVersionUID = 3L;
	public String id;
	public String title;
	
	public String readStringFromTag(JsonReader reader, String tagStatic) throws IOException
	{
		String tag=reader.nextName();
		if(tag.compareTo(tagStatic)!=0) throw new IOException("tag name error tag="+tag);
		return reader.nextString();
	}
	
	public void readBaseMember(JsonReader reader, String tagId, String tagTitle) throws IOException
	{
		try {
			id=readStringFromTag(reader, tagId);
			title=readStringFromTag(reader, tagTitle);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static ArrayList<String> seperateStringByPipe(String s)
	{
		String sep="|";
		String [] res=s.split(sep);
		ArrayList<String> alS=new ArrayList<String>(32);
		for(String ss: res)
		{
			if(ss.length()>0 && ss.compareTo(sep)!=0) alS.add(ss);
		}
		return alS;
	}
	public Boolean readBoolFromTag(JsonReader reader, String tagStatic) throws IOException
	{
		String res=readStringFromTag(reader, tagStatic);
		return res.compareTo("1")==0 ? true : false;
	}
	public int readIntegerFromTag(JsonReader reader, String tagStatic) throws IOException
	{
		String res=readStringFromTag(reader, tagStatic);
		return Integer.decode(res);
		
	}
}
